<?php
session_start();
include '../import_admin.php';
checkUserLogin();

$response_array = array();
$response_array[STATUS] = STATUS_OK;
$content = "";

// check contrller
if (! isset( $_REQUEST[PARAM_CONTROLLER]) || empty( $_REQUEST[PARAM_CONTROLLER])) {
    
    $response_array[STATUS] = STATUS_ERROR;
    $response_array[MESSAGE] = MESSAGE_NOT_DEFINE_CONTROLLER;

} else 
    if (! isset( $_REQUEST[PARAM_ACTION]) || empty( $_REQUEST[PARAM_ACTION])) { // check action
        
        $response_array[STATUS] = STATUS_ERROR;
        $response_array[MESSAGE] = MESSAGE_NOT_DEFINE_ACTION;
    
    } else {
        
        // get controller and action
        $controller = $_REQUEST[PARAM_CONTROLLER];
        $action = $_REQUEST[PARAM_ACTION];
        
        // check user permission
        if (! checkAccessPermision( $_SESSION[SESSION_ROLE], $controller, $action)) {
            
            $response_array[STATUS] = STATUS_DECLINED;
            $response_array[MESSAGE] = MESSAGE_ACCESS_DECLINED;
        
        } else {
            
            // swich controller
            switch ($controller) {
                case PVALUE_CONTROLLER_PAGE_WEBINFO : // PVALUE_CONTROLLER_PAGE_WEBINFO
                    $ctrl = new WebsiteController();
                    switch ($action) {
                        case PVALUE_ACTION_VIEW_TABLE :
                            $content = $ctrl->viewTable();
                            break;
                        
                        case PVALUE_ACTION_VIEW_GRID :
                            $content = $ctrl->viewGrid();
                            break;
                        
                        case PVALUE_ACTION_VIEW_SORT :
                            $content = $ctrl->viewSort();
                            break;
                        
                        case PVALUE_ACTION_VIEW_FORM :
                            $content = $ctrl->viewForm();
                            break;
                    }
                    break;
                
                case PVALUE_CONTROLLER_PAGE_ORGANINFO : // PVALUE_CONTROLLER_PAGE_ORGANINFO
                    $ctrl = new OrganInfoController();
                    switch ($action) {
                        case PVALUE_ACTION_VIEW_TABLE :
                            $content = $ctrl->viewTable();
                            break;
                        
                        case PVALUE_ACTION_VIEW_GRID :
                            $content = $ctrl->viewGrid();
                            break;
                        
                        case PVALUE_ACTION_VIEW_SORT :
                            $content = $ctrl->viewSort();
                            break;
                        
                        case PVALUE_ACTION_VIEW_FORM :
                            $content = $ctrl->viewForm();
                            break;
                    }
                    break;
                
                case PVALUE_CONTROLLER_PAGE_USERS : // PVALUE_CONTROLLER_PAGE_USERS
                    $ctrl = new UserController();
                    switch ($action) {
                        case PVALUE_ACTION_VIEW_PROFILE :
                            $content = $ctrl->viewProfile();
                            break;
                        
                        case PVALUE_ACTION_VIEW_CHANGEPASSWORD :
                            $content = $ctrl->viewChangePassword();
                            break;
                        
                        case PVALUE_ACTION_VIEW_ACTION :
                            $content = $ctrl->viewHistoryAction();
                            break;
                    }
                    break;
                
                case PVALUE_CONTROLLER_PAGE_ACCOUNT : // PVALUE_CONTROLLER_PAGE_ACCOUNT
                    $ctrl = new AccountController();
                    switch ($action) {
                        case PVALUE_ACTION_VIEW_TABLE :
                            $content = $ctrl->viewTable();
                            break;
                        
                        case PVALUE_ACTION_VIEW_GRID :
                            $content = $ctrl->viewGrid();
                            break;
                        
                        case PVALUE_ACTION_VIEW_SORT :
                            $content = $ctrl->viewSort();
                            break;
                        
                        case PVALUE_ACTION_VIEW_FORM :
                            $content = $ctrl->viewForm();
                            break;
                    }
                    break;
                    
                case PVALUE_CONTROLLER_PAGE_PAGESUPPORT : // PVALUE_CONTROLLER_PAGE_PAGESUPPORT
                    $ctrl = new SupportController();
                    switch ($action) {
                        case PVALUE_ACTION_VIEW_TABLE :
                            $content = $ctrl->viewTable();
                            break;
                        
                        case PVALUE_ACTION_VIEW_GRID :
                            $content = $ctrl->viewGrid();
                            break;
                        
                        case PVALUE_ACTION_VIEW_SORT :
                            $content = $ctrl->viewSort();
                            break;
                        
                        case PVALUE_ACTION_VIEW_FORM :
                            $content = $ctrl->viewForm();
                            break;
                    }
                    break;
                
                case PVALUE_CONTROLLER_PAGE_PAGEIMAGES : // PVALUE_CONTROLLER_PAGE_PAGEIMAGES
                    $ctrl = new PageImageController();
                    switch ($action) {
                        case PVALUE_ACTION_VIEW_FILEBROWSER :
                            $content = $ctrl->viewFileManager();
                            break;
                        
                        case PVALUE_ACTION_VIEW_GRID :
                            $content = $ctrl->viewGrid();
                            break;
                        
                        case PVALUE_ACTION_VIEW_SORT :
                            $content = $ctrl->viewSort();
                            break;
                        
                        case PVALUE_ACTION_VIEW_FORM :
                            $content = $ctrl->viewForm();
                            break;
                    }
                    break;
                
                case PVALUE_CONTROLLER_PAGE_PAGEPOPUP : // PVALUE_CONTROLLER_PAGE_PAGEPOPUP
                    $ctrl = new PopupController();
                    switch ($action) {
                        case PVALUE_ACTION_VIEW_POPUP :
                            $content = $ctrl->viewPopup();
                            break;
                        
                        case PVALUE_ACTION_VIEW_FORM :
                            $content = $ctrl->viewForm();
                            break;
                    }
                    break;
                
                case PVALUE_CONTROLLER_VIEW_CATEGORIES : // PVALUE_CONTROLLER_VIEW_CATEGORIES
                    $ctrl = new CategoryController();
                    switch ($action) {
                        case PVALUE_ACTION_VIEW_TABLE :
                            $content = $ctrl->viewTable();
                            break;
                        
                        case PVALUE_ACTION_VIEW_GRID :
                            $content = $ctrl->viewGrid();
                            break;
                        
                        case PVALUE_ACTION_VIEW_SORT :
                            $content = $ctrl->viewSort();
                            break;
                        
                        case PVALUE_ACTION_VIEW_FORM :
                            $content = $ctrl->viewForm();
                            break;
                    }
                    break;
                
                case PVALUE_CONTROLLER_VIEW_ARTICLES : // PVALUE_CONTROLLER_VIEW_ARTICLES
                    $ctrl = new ArticleController();
                    switch ($action) {
                        case PVALUE_ACTION_VIEW_TABLE :
                            $content = $ctrl->viewTable();
                            break;
                        
                        case PVALUE_ACTION_VIEW_GRID :
                            $content = $ctrl->viewGrid();
                            break;
                        
                        case PVALUE_ACTION_VIEW_SORT :
                            $content = $ctrl->viewSort();
                            break;
                        
                        case PVALUE_ACTION_VIEW_FORM :
                            $content = $ctrl->viewForm();
                            break;
                    }
                    break;
                    
                    
                case PVALUE_CONTROLLER_VIEW_PRODUCTS : // PVALUE_CONTROLLER_VIEW_PRODUCTS
                    $ctrl = new ProductController();
                    switch ($action) {
                        case PVALUE_ACTION_VIEW_TABLE :
                            $content = $ctrl->viewTable();
                            break;
                        
                        case PVALUE_ACTION_VIEW_GRID :
                            $content = $ctrl->viewGrid();
                            break;
                        
                        case PVALUE_ACTION_VIEW_SORT :
                            $content = $ctrl->viewSort();
                            break;
                        
                        case PVALUE_ACTION_VIEW_FORM :
                            $content = $ctrl->viewForm();
                            break;
                    }
                    break;
                
                    
                case PVALUE_CONTROLLER_PAGE_PRODUCTIMAGES : // PVALUE_CONTROLLER_VIEW_PRODUCTS
                    $ctrl = new ProductImageController();
                    switch ($action) {
                        case PVALUE_ACTION_VIEW_TABLE :
                            $content = $ctrl->viewTable();
                            break;
                        
                        case PVALUE_ACTION_VIEW_GRID :
                            $content = $ctrl->viewGrid();
                            break;
                        
                        case PVALUE_ACTION_VIEW_SORT :
                            $content = $ctrl->viewSort();
                            break;
                        
                        case PVALUE_ACTION_VIEW_FORM :
                            $content = $ctrl->viewForm();
                            break;
                    }
                    break;
                
                case PVALUE_CONTROLLER_VIEW_ALBUMS : // PVALUE_CONTROLLER_VIEW_ALBUMS
                    $ctrl = new AlbumController();
                    switch ($action) {
                        case PVALUE_ACTION_VIEW_TABLE :
                            $content = $ctrl->viewTable();
                            break;
                        
                        case PVALUE_ACTION_VIEW_GRID :
                            $content = $ctrl->viewGrid();
                            break;
                        
                        case PVALUE_ACTION_VIEW_SORT :
                            $content = $ctrl->viewSort();
                            break;
                        
                        case PVALUE_ACTION_VIEW_FORM :
                            $content = $ctrl->viewForm();
                            break;
                    }
                    break;
                
                case PVALUE_CONTROLLER_VIEW_FILES : // PVALUE_CONTROLLER_VIEW_IMAGES
                    $ctrl = new FileController();
                    switch ($action) {
                        case PVALUE_ACTION_VIEW_TABLE :
                            $content = $ctrl->viewTable();
                            break;
                        
                        case PVALUE_ACTION_VIEW_GRID :
                            $content = $ctrl->viewGrid();
                            break;
                        
                        case PVALUE_ACTION_VIEW_SORT :
                            $content = $ctrl->viewSort();
                            break;
                        
                        case PVALUE_ACTION_VIEW_FORM :
                            $content = $ctrl->viewForm();
                            break;
                    }
                    break;
                    
                case PVALUE_CONTROLLER_VIEW_IMAGES : // PVALUE_CONTROLLER_VIEW_IMAGES
                    $ctrl = new ImagesController();
                    switch ($action) {
                        case PVALUE_ACTION_VIEW_TABLE :
                            $content = $ctrl->viewTable();
                            break;
                        
                        case PVALUE_ACTION_VIEW_GRID :
                            $content = $ctrl->viewGrid();
                            break;
                        
                        case PVALUE_ACTION_VIEW_SORT :
                            $content = $ctrl->viewSort();
                            break;
                        
                        case PVALUE_ACTION_VIEW_FORM :
                            $content = $ctrl->viewForm();
                            break;
                    }
                    break;
                
                case PVALUE_CONTROLLER_VIEW_VIDEOS : // PVALUE_CONTROLLER_VIEW_VIDEOS
                    $ctrl = new VideosController();
                    switch ($action) {
                        case PVALUE_ACTION_VIEW_TABLE :
                            $content = $ctrl->viewTable();
                            break;
                        
                        case PVALUE_ACTION_VIEW_GRID :
                            $content = $ctrl->viewGrid();
                            break;
                        
                        case PVALUE_ACTION_VIEW_SORT :
                            $content = $ctrl->viewSort();
                            break;
                        
                        case PVALUE_ACTION_VIEW_FORM :
                            $content = $ctrl->viewForm();
                            break;
                    }
                    break;
                
                default :
                    $response_array[STATUS] = STATUS_ERROR;
                    $response_array[MESSAGE] = MESSAGE_NOT_DEFINE_CONTROLLER;
                    break;
            }
            
            // check status
            if ($response_array[STATUS] == STATUS_OK) {
                $layout = new LayoutController();
                switch ($action) {
                    case PVALUE_ACTION_VIEW_TABLE :
                        echo $layout->viewTable( $content);
                        break;
                    
                    case PVALUE_ACTION_VIEW_GRID :
                        echo $layout->viewGrid( $content);
                        break;
                    
                    case PVALUE_ACTION_VIEW_SORT :
                        echo $layout->viewSort( $content);
                        break;
                    
                    case PVALUE_ACTION_VIEW_FORM :
                        echo $layout->viewForm( $content);
                        break;
                    
                    case PVALUE_ACTION_VIEW_PROFILE :
                        echo $layout->viewForm( $content);
                        break;
                    
                    case PVALUE_ACTION_VIEW_CHANGEPASSWORD :
                        echo $layout->viewForm( $content);
                        break;
                    
                    case PVALUE_ACTION_VIEW_ACTION :
                        echo $layout->viewForm( $content);
                        break;
                    
                    case PVALUE_ACTION_VIEW_POPUP :
                        echo $layout->viewForm( $content);
                        break;
                    
                    default :
                        echo $content;
                        break;
                }
            } else {
            
            }
        
        }
    
    }

// echo $response_array[MESSAGE];echo $_SESSION[SESSION_LANGUAGE];

?>